import { ITEM_INFO, ITEM_SEARCH, ITEM_SEARCH_HOT, ITEM_RECOMMEND } from '@constants/item'

const INITIAL_STATE = {
  searchInfo: {
    page: 1,
    list: []
  },
}

export default function item(state = INITIAL_STATE, action) {
  switch(action.type) {
    case ITEM_INFO: {
      return {
        ...state
      }
    }
    case ITEM_SEARCH: {
      const { hasMore, page, list } = action.payload
      if (list.length > 0) {
        if (page == 0) {
          return {
            ...state,
            searchInfo: { list: list, hasMore: hasMore, page: page+2 }
          }
        } else {
          return {
            ...state,
            searchInfo: { list: state.searchInfo.list.concat(list), hasMore: hasMore, page: page+2 }
          }
        }
      }
    }
    case ITEM_SEARCH_HOT: {
      return {
        ...state
      }
    }
    case ITEM_RECOMMEND: {
      return {
        ...state
      }
    }
    default:
      return state
  }
}
